package com.example.lishop.service.impl

import com.example.lishop.entity.BProductTagEntity
import com.example.lishop.exception.ExceptEnum
import com.example.lishop.repository.ProductTagRepository
import com.example.lishop.service.ProductTagService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.springframework.util.Assert

/**
 * Created on 2021/3/14 18:14
 * @author shuguo
 */
@Service
class ProductTagServiceImpl : ProductTagService {

    @Autowired
    lateinit var repository: ProductTagRepository

    override fun add(data: BProductTagEntity): BProductTagEntity {
        return repository.save(data)
    }

    override fun update(data: BProductTagEntity) {
        detail(data)
        return repository.update(data.productTagId, data.name, data.descript, data.sts)
    }

    override fun del(data: BProductTagEntity) {
        detail(data)
        repository.del(data.productTagId)
    }

    override fun list(): List<BProductTagEntity> {
        return repository.findAll()
    }

    override fun detail(data: BProductTagEntity): BProductTagEntity? {
        val result = repository.findByProductTagId(data.productTagId)
        Assert.notNull(result, ExceptEnum.NOT_EXIST)
        return result
    }

}